package com.briup.srms.sms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.srms.sms.bean.Channel;
import com.briup.srms.sms.bean.extend.ChannelExtend;
import com.briup.srms.sms.dao.ChannelMapper;
import com.briup.srms.sms.dao.extend.ChannelExtendMapper;
import com.briup.srms.sms.service.IChannelService;
import com.jacky.base.utils.CustomerException;
import com.jacky.base.utils.PageVM;

@Service
public class ChannelServiceImpl implements IChannelService {
	@Autowired
	private ChannelMapper channelMapper;
	@Autowired
	private ChannelExtendMapper channelExtendMapper;

	@Override
	public PageVM<ChannelExtend> queryTree(int page,int pageSize,String name) {
		List<ChannelExtend> list = channelExtendMapper.queryTree(page,pageSize,name);
		long total = channelExtendMapper.count(name);
		return new PageVM<>(page, pageSize, total, list);
	}

	@Override
	public void deleteById(long id) throws CustomerException {
		Channel channel = channelMapper.selectByPrimaryKey(id);
		if(channel == null) {
			throw new CustomerException("要删除渠道信息不存在");
		}
		channelMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void saveOrUpdate(Channel channel) throws CustomerException {
		if(channel.getId() == null) {
			channelMapper.insert(channel);
		} else {
			channelMapper.updateByPrimaryKey(channel);
		}
	}

}
